home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / DivX / VFW4048src / src / maintenance.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-21  |  8.0 KB  |  249 lines

  1.  
  2. /**************************************************************************
  3.  *                                                                        *
  4.  * This code is developed by Adam Li.  This software is an                *
  5.  * implementation of a part of one or more MPEG-4 Video tools as          *
  6.  * specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
  7.  * software module in hardware or software products are advised that its  *
  8.  * use may infringe existing patents or copyrights, and any such use      *
  9.  * would be at such party's own risk.  The original developer of this     *
  10.  * software module and his/her company, and subsequent editors and their  *
  11.  * companies (including Project Mayo), will have no liability for use of  *
  12.  * this software or modifications or derivatives thereof.                 *
  13.  *                                                                        *
  14.  * Project Mayo gives users of the Codec a license to this software       *
  15.  * module or modifications thereof for use in hardware or software        *
  16.  * products claiming conformance to the MPEG-4 Video Standard as          *
  17.  * described in the Open DivX license.                                    *
  18.  *                                                                        *
  19.  * The complete Open DivX license can be found at                         *
  20.  * http://www.projectmayo.com/opendivx/license.php .                      *
  21.  *                                                                        *
  22.  **************************************************************************/
  23.  
  24. /*************************************************************************
  25.  *
  26.  *  Maintenance.cpp, Maintenance functions
  27.  *
  28.  *  Copyright (C) 2000  DivX Networks
  29.  * 
  30.  *  Adam Li
  31.  *  Andrea Graziani
  32.  *
  33.  *  DivX Advance Research Center <darc@projectmayo.com>
  34.  *
  35.  ************************************************************************/
  36.  
  37. // This includes the maintance functions of the driver. There are functions
  38. // that answers the various info query messages, and configuration of 
  39. // the codec.
  40.  
  41. #include "stdafx.h"
  42. #include "codec.h"
  43. #include "resource.h"
  44. #include "config_dialog.h"
  45.  
  46. codec::codec()
  47. {
  48. }
  49.  
  50. codec::~codec()
  51. {
  52. }
  53.  
  54. long codec::getInfo(LPARAM lParam1, LPARAM lParam2)
  55. {
  56.     ICINFO *info = (ICINFO *)lParam1;
  57.  
  58.     info->fccType = ICTYPE_VIDEO;
  59.     info->fccHandler = mmioFOURCC('D', 'I', 'V', 'X');
  60.     info->dwFlags = 
  61.         VIDCF_FASTTEMPORALC | VIDCF_FASTTEMPORALD; 
  62.     info->dwVersion = 0;
  63.     info->dwVersionICM = ICVERSION;
  64.     wcscpy(info->szName, L"DivX codec"); 
  65.     wcscpy(info->szDescription, L"DivX MPEG-4 Codec (Alpha 4.8)");
  66.  
  67.     return lParam2;
  68. }
  69.  
  70. long codec::about(LPARAM lParam1, LPARAM lParam2)
  71. {
  72.     if (lParam1 == -1) return ICERR_OK;
  73.     CDialog dlgAbout(IDD_DIALOG_ABOUT, NULL/*&wndParent*/);
  74.     dlgAbout.DoModal();
  75.     return ICERR_OK;
  76. }
  77.  
  78. long codec::config(LPARAM lParam1, LPARAM lParam2)
  79. {
  80.     if (lParam1 == -1) return ICERR_OK;
  81. //    CDialog dlgConfig(IDD_DIALOG_CONFIG, NULL/*&wndParent*/);
  82.     ConfigDialog dlgConfig(NULL/*&wndParent*/);
  83.     dlgConfig.m_bitrate = bitrate / 1000;
  84.     dlgConfig.m_rc_period = rc_period;
  85.     dlgConfig.m_max_quant = max_quantizer;
  86.     dlgConfig.m_min_quant = min_quantizer;
  87.     dlgConfig.m_search_range.Format("%d", search_range);
  88.     if (dlgConfig.DoModal() == IDOK) {
  89.         bitrate = dlgConfig.m_bitrate * 1000;
  90.         rc_period = dlgConfig.m_rc_period;
  91.         max_quantizer = dlgConfig.m_max_quant;
  92.         min_quantizer = dlgConfig.m_min_quant;
  93.         search_range = atoi(dlgConfig.m_search_range);
  94.     }
  95.  
  96.     return ICERR_OK;
  97. }
  98.  
  99. long codec::encGetFormat(LPARAM lParam1, LPARAM lParam2)
  100. {
  101.     BITMAPINFO *lpbiInput, *lpbiOutput;
  102.     BITMAPV4HEADER *infohdr;
  103.     long x_dim, y_dim;
  104.  
  105.     lpbiInput = (BITMAPINFO *)lParam1;
  106.     lpbiOutput = (BITMAPINFO *)lParam2;
  107.  
  108.     if (lpbiOutput == NULL) return(sizeof(BITMAPV4HEADER) + sizeof(RGBQUAD));
  109.  
  110.     // everything is copied from the input, including the dimensions
  111.     *lpbiOutput = *lpbiInput;
  112.     infohdr = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
  113.     x_dim = infohdr->bV4Width;
  114.     y_dim = infohdr->bV4Height;
  115.  
  116.     infohdr->bV4BitCount = 0;
  117.     infohdr->bV4V4Compression = FOURCC_DIVX;
  118.     infohdr->bV4SizeImage = x_dim * y_dim * 3 / 2 * sizeof(short int);
  119.     return(ICERR_OK);
  120. }
  121.  
  122. long codec::encGetSize(LPARAM lParam1, LPARAM lParam2)
  123. {
  124.     BITMAPINFO *lpbiInput, *lpbiOutput;
  125.     BITMAPV4HEADER *infohdr;
  126.     long x_dim, y_dim;
  127.  
  128.     lpbiInput = (BITMAPINFO *)lParam1;
  129.     lpbiOutput = (BITMAPINFO *)lParam2;
  130.  
  131.     infohdr = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
  132.     x_dim = infohdr->bV4Width;
  133.     y_dim = infohdr->bV4Height;
  134.  
  135.     return(x_dim * y_dim * 3 / 2 * sizeof(short int));
  136. }
  137.  
  138. long codec::encQuery(LPARAM lParam1, LPARAM lParam2)
  139. {
  140.     BITMAPINFO *lpbiInput, *lpbiOutput;
  141.     BITMAPV4HEADER *infohdr_i, *infohdr_o;
  142.     long x_dim_i, y_dim_i, x_dim_o, y_dim_o;
  143.  
  144.     lpbiInput = (BITMAPINFO *)lParam1;
  145.     lpbiOutput = (BITMAPINFO *)lParam2;
  146.  
  147.     infohdr_i = (BITMAPV4HEADER *)&(lpbiInput->bmiHeader);
  148.     x_dim_i = infohdr_i->bV4Width;
  149.     y_dim_i = infohdr_i->bV4Height;
  150.  
  151.     // input dimension has to be divicable by 16
  152.     if ((x_dim_i % 16) || (y_dim_i % 16)) return (ICERR_BADFORMAT);
  153.     // input format has to be un-compressed 24-bit RGB
  154. //    if ((infohdr_i->bV4V4Compression != BI_RGB)
  155. //        || (infohdr_i->bV4BitCount != 24)) return (ICERR_BADFORMAT);
  156.     if (getImageType(infohdr_i) == 0) return (ICERR_BADFORMAT);
  157.  
  158.     if (lpbiOutput == NULL) return (ICERR_OK);
  159.  
  160.     infohdr_o = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
  161.     x_dim_o = infohdr_o->bV4Width;
  162.     y_dim_o = infohdr_o->bV4Height;
  163.  
  164.     // output dimension must be exactly same as the input dimension
  165.     if ((x_dim_o != x_dim_i) || (y_dim_o != y_dim_i)) return (ICERR_BADFORMAT);
  166.     // output format must be DivX with BitCount 0
  167.     if ((infohdr_o->bV4V4Compression != FOURCC_DIVX)
  168.         || (infohdr_o->bV4BitCount != 0)) return (ICERR_BADFORMAT);
  169.  
  170.     return(ICERR_OK);
  171. }
  172.  
  173. long codec::encFramesInfo(LPARAM lParam1, LPARAM lParam2)
  174. {
  175.     ICCOMPRESSFRAMES *icf;
  176.     long icfSize;
  177.  
  178.     icf = (ICCOMPRESSFRAMES *)lParam1;
  179.     icfSize = (long)lParam2;
  180.  
  181.     framerate = (float)icf->dwRate / (float)icf->dwScale;
  182.  
  183.     return(ICERR_OK);
  184. }
  185.  
  186. long codec::decGetFormat(LPARAM lParam1, LPARAM lParam2)
  187. {
  188.     BITMAPINFO *lpbiInput, *lpbiOutput;
  189.     BITMAPV4HEADER *infohdr;
  190.     long x_dim, y_dim;
  191.  
  192.     lpbiInput = (BITMAPINFO *)lParam1;
  193.     lpbiOutput = (BITMAPINFO *)lParam2;
  194.  
  195.     if (lpbiOutput == 0)
  196.         return (sizeof(BITMAPV4HEADER) + sizeof(RGBQUAD));
  197.  
  198.     // everything is copied from the input, including the dimensions
  199.     *lpbiOutput = *lpbiInput;
  200.     infohdr = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
  201.     x_dim = infohdr->bV4Width;
  202.     y_dim = infohdr->bV4Height;
  203.  
  204.     infohdr->bV4BitCount = 24;
  205.     infohdr->bV4V4Compression = BI_RGB;
  206.     infohdr->bV4SizeImage = x_dim * y_dim * 3;
  207.  
  208.     return ICERR_OK;
  209. }
  210.  
  211. long codec::decQuery(LPARAM lParam1, LPARAM lParam2)
  212. {
  213.     BITMAPINFO *lpbiInput, *lpbiOutput;
  214.     BITMAPV4HEADER *infohdr_i, *infohdr_o;
  215.     long x_dim_i, y_dim_i, x_dim_o, y_dim_o;
  216.  
  217.     lpbiInput = (BITMAPINFO *)lParam1;
  218.     lpbiOutput = (BITMAPINFO *)lParam2;
  219.  
  220.     infohdr_i = (BITMAPV4HEADER *)&(lpbiInput->bmiHeader);
  221.     x_dim_i = infohdr_i->bV4Width;
  222.     y_dim_i = infohdr_i->bV4Height;
  223.  
  224.     // input supported features
  225.     if ((x_dim_i % 16) || (y_dim_i % 16)) 
  226.         return ICERR_BADFORMAT; // input dimension has to be divicable by 16
  227.     if (!((infohdr_i->bV4V4Compression == FOURCC_DIVX) || (infohdr_i->bV4V4Compression == 4L /* BI_JPEG */))
  228.         || (infohdr_i->bV4BitCount != 0)) 
  229.         return ICERR_BADFORMAT; // input format must be DivX with BitCount 0
  230.  
  231.     if (lpbiOutput == NULL) 
  232.         return ICERR_OK;
  233.  
  234.     infohdr_o = (BITMAPV4HEADER *)&(lpbiOutput->bmiHeader);
  235.     x_dim_o = infohdr_o->bV4Width;
  236.     y_dim_o = infohdr_o->bV4Height;
  237.  
  238.     // output supported features
  239.     if ((x_dim_o != x_dim_i) || (y_dim_o != y_dim_i)) 
  240.         return ICERR_BADFORMAT; // output dimension must be exactly same as the input dimension
  241.     if (infohdr_o->bV4V4Compression != BI_RGB)    
  242.         return ICERR_BADFORMAT; // output format has to be uncompressed
  243.     if ((infohdr_o->bV4BitCount < 16) || (infohdr_o->bV4BitCount > 32))
  244.         return ICERR_BADFORMAT;
  245.  
  246.     return ICERR_OK;
  247. }
  248.  
  249.